package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.Game;
import com.itheima.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Name GameController
 * @Author BaiXin
 * @Date 2022-10-21 21:04
 */
@RestController
@RequestMapping("/game")
public class GameController {
    @Autowired
    private GameService gameService;

    @GetMapping
    public Result findAll(){
        List<Game> gameList = gameService.findAll();
        return Result.success(20041,"查询成功", gameList);
    }

    @PostMapping
    public Result save(@RequestBody Game game){
         gameService.save(game);
         return Result.success(20011,"保存成功",null);
    }

    @PutMapping
    public Result update(@RequestBody Game game){
        gameService.update(game);
        return Result.success(20031,"修改成功",null);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        gameService.deleteById(id);
        return Result.success(20021,"删除成功",null);

    }


}
